
import { define , WeElement } from 'omi';

import { get, createOrder, toastSuccess, toastErr } from '../../../utils/util'

import './index.css'
import api from '../../../api/api';
import logo from './star.png'
import logobg from './starbg.png'
const app = getApp();
define('index', class extends WeElement{
    config={
      navigationBarTitleText:""
    }

    data = {
        banner:[],
        datail:[],
        goods:{
            name:'酸菜鱼',
            money: 30,
            sale: 1000,
            like:100,
            
        },
        bgcolor: true,
        bool:"",
        idnum:-1,
        comid:-1
    }
    
    install(option){
      let { id, comid } = option ;
        this.data.idnum=id;
      this.data.comid = comid
      console.log(option,"option")
      get(api.ShopfooddetailUrl, { goods_id: id }).then((r) => {
        console.log(r)
        this.data.banner = r.data.goods_carousel
        this.data.detail = r.data.goods_detail
        this.update();
        console.log(this.data.banner)
      })
      // wx.getStorage({
      //   key: 'key',
      //   success(res) {
      //     console.log(res.data,"res.data")
      //   }
      // })
    }
  collcet=()=>{
    this.data.bool = !this.data.bool
    if (!this.data.bool){
      this.data.bool=false
      this.data.bgcolor = false
      app.globalData.idmunber = this.data.comid
      console.log(app.globalData.idmunber)
    }else{
      this.data.bool = true
      this.data.bgcolor = true
    }
    wx.setStorage({
      key: 'key',
      data: this.data.bgcolor
    })
   
    this.update();
  }
    render(){
      let { banner} = this.data
        return (
            <view class='page'>
                {/* 轮播 */}
                <swiper indicator-dots={true} > 
                    { banner.map((item,index)=>(
                <swiper-item key={index}>
                  <image src={item}></image>
                </swiper-item>
                )
                    )
                    
                    }
                </swiper>
                {/*  */}
                
              <view class='good_detail_warp' >
              <view>{detail.goods_name}</view>
                <view>
                <view>月销</view>
                <view>好评度 {detail.favorable}%</view>
                </view>
              <view>&yen;{detail.goods_price}</view>
              
              <view class="image_box" bindtap='collcet'>
                {
                  bgcolor?<image src={logo}></image>:<image src={logobg}> </image>
                }
                 </view>
              </view>
                
               
                
                <view class='good_detail_warp' >
                    <view>商品详情</view>
                    <view>
                        <view>主料:</view>
                <view>{detail.main_material}</view>
                    </view>
                    <view>
                        <view>辅料:</view>
                <view>{detail.accessories}</view>
                    </view>
                    <view>
                        <view>荤素:</view>
                <view>{detail.is_meat}</view>
                    </view>
                    <view>
                        <view>口味:</view>
                <view>{detail.flavor}</view>
                    </view>
                    <view>
                        <view>制作方式:</view>
                <view>{detail.cookie_method}</view>
                    </view>
                </view>
            </view>
        )
    }


})